////
////  JXEmoticonView.swift
////  swift高仿微博
////
////  Created by peijiaxing on 16/3/9.
////  Copyright © 2016年 peijiaxing. All rights reserved.
////
//
//import UIKit
//
//let JXEmoticonViewReuseIdentifier = "JXEmoticonViewReuseIdentifier"
//
//class JXEmoticonView: UIView
//,UICollectionViewDataSource{
//
//    override init(frame: CGRect) {
//        super.init(frame: frame)
//        setupUI()
//        setupCollectionView()
//    }
//
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//   
//    private func setupUI(){
//        
//        addSubview(collectionView)
//        addSubview(toolBarView)
//        collectionView.snp_makeConstraints { (make) -> Void in
//            make.top.equalTo(self.snp_top)
//            make.left.equalTo(self.snp_left)
//            make.right.equalTo(self.snp_right)
//            make.bottom.equalTo(toolBarView.snp_top)
//            
//        }
//        
//        toolBarView.snp_makeConstraints { (make) -> Void in
//            make.left.equalTo(self.snp_left)
//            make.bottom.equalTo(self.snp_bottom)
//            make.right.equalTo(self.snp_right)
//            make.height.equalTo(40)
//        }
//        
//    }
//    
//    // MARK: --- 设置collectionView 属性
//    private func setupCollectionView(){
//        // 设置数据源
//        collectionView.dataSource = self
////        // 注册 cell
//        collectionView.registerClass(JXEmoticonCollectionViewCell.self, forCellWithReuseIdentifier:JXEmoticonViewReuseIdentifier )
//        
//        // 改变滑动方向
//        flowLayout.scrollDirection = .Horizontal
//        // 去掉滚动提示
//        collectionView.showsHorizontalScrollIndicator = false
//        collectionView.showsVerticalScrollIndicator = false
//        
//        collectionView.pagingEnabled = true
//    }
//    
//    override func layoutSubviews() {
//        super.layoutSubviews()
//        
//        //设置item
//        flowLayout.itemSize = CGSizeMake(UIScreen.mainScreen().bounds.size.width,collectionView.frame.height)
//        flowLayout.minimumInteritemSpacing = 0
//        flowLayout.minimumLineSpacing = 0
//
//    }
//    
//    // MARK:--- 懒加载
//     // 用自动布局
//    private lazy var flowLayout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
//    
//    private lazy var collectionView: UICollectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: self.flowLayout)
//    
//   
//    // 下边 是自定义的 UIView
//    private lazy var toolBarView: JXEmoticonToolBarView = JXEmoticonToolBarView()
//    
//    
//
//}
//
////MARK:-- UICollectionViewDataSource
//extension JXEmoticonView{
//    
//    
//    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//        return 4
//    }
//    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
//        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(JXEmoticonViewReuseIdentifier, forIndexPath: indexPath) as! JXEmoticonCollectionViewCell
//       
//        // 根据对应的数组下标去获取表情
//        //也可以根据数组对应的下标去获取表情
//        cell.JXlabel.text = "第\(indexPath.section)部分 第\(indexPath.row)item"
//        
//        return cell
//    }
//    
//}
//
//// MARK:-- 自定义cell
//class JXEmoticonCollectionViewCell:UICollectionViewCell{
//    
//    override init(frame: CGRect) {
//        super.init(frame: frame)
//    
//        setupUI()
//        
//    }
//
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//    
//    private func setupUI(){
//        
//        backgroundColor = UIColor.blueColor()
//        
//        contentView.addSubview(JXlabel)
//        
//        JXlabel.snp_makeConstraints { (make) -> Void in
//            make.center.equalTo(self.center)
//        }
//        
//    }
//    
//    // 自定义一个label
//    private lazy var JXlabel : UILabel = {
//       let label = UILabel()
//        
//        label.font = UIFont.systemFontOfSize(15)
//        
//        return label
//        
//        
//    }()
//}
//
///
//  CZEmoticonView.swift
//  Weibo24
//
//  Created by apple on 16/3/7.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

/*
界面 --
功能
*/
let JXEmoticonViewReuseIdentifier = "JXEmoticonViewReuseIdentifier"
class JXEmoticonView: UIView ,UICollectionViewDataSource{
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
        setupCollectionView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:--添加控件和设置属性
    private func setupUI(){
        
        //
        addSubview(collectionView)
        addSubview(toolBarView)
        
        toolBarView.backgroundColor = UIColor.greenColor()
        
        //设置约束 左边,上边,右边,下边是 toolBarView的顶部
        collectionView.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(toolBarView.snp_top)
            
        }
        
        // 左边,底部,右边,高度
        toolBarView.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(self.snp_bottom)
            make.height.equalTo(40)
            
        }
        
    }
    
    //MARK:--设置collectionView的属性
    private func setupCollectionView(){
        
        //设置数据源方法
        
        collectionView.dataSource = self
        
        //注册cell
        collectionView.registerClass(JXEmoticonCollectionViewCell.self, forCellWithReuseIdentifier: JXEmoticonViewReuseIdentifier)
        //改变滑动方向
        flowLayout.scrollDirection = .Horizontal
        
        //去掉滚动的提示
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.showsVerticalScrollIndicator = false
        
        collectionView.pagingEnabled = true
        
        
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //设置item
        flowLayout.itemSize = CGSizeMake(UIScreen.mainScreen().bounds.size.width,collectionView.frame.height)
        flowLayout.minimumInteritemSpacing = 0
        flowLayout.minimumLineSpacing = 0
    }
    
    //MARK:--懒加载
    
    //上边 是用 UICollectionView实现
    private lazy var flowLayout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    
    private lazy var collectionView: UICollectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: self.flowLayout)
    
    // 下边 是自定义的 UIView
    private lazy var toolBarView: JXEmoticonToolBarView = JXEmoticonToolBarView()
    
    
}

//MARK:-- UICollectionViewDataSource
extension JXEmoticonView {
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        //        CZEmoticonManager.readEmotions()
        
//        return JXEmoticonManager.getAllEmoticons().count

        return 2
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//        return JXEmoticonManager.getAllEmoticons()[section].count

        return 3
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(JXEmoticonViewReuseIdentifier, forIndexPath: indexPath) as! JXEmoticonCollectionViewCell
        
        //也可以根据数组对应的下标去获取表情
        cell.label.text = "第\(indexPath.section)部分 第\(indexPath.row)item"
        
        return cell
    }
    
}

//自定义一个cell,然后在cell里放一个label
class JXEmoticonCollectionViewCell: UICollectionViewCell{
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        backgroundColor = UIColor.blueColor()
        
        contentView.addSubview(label)
        
        label.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(contentView.snp_center)
        }
        
    }
    
    //MARK:--懒加载
    private var label: UILabel = {
        
        let label = UILabel()
        
        label.font = UIFont.systemFontOfSize(18)
        
        
        return label
    }()
    
    
}

